package com.acquisition.task.util;

import com.dcs.cn.common.database.dao.BaseDao;
import com.dcs.cn.common.database.dao.impl.BaseDaoImpl;
import com.dcs.cn.common.domain.CodeHj212;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * hj212监测因子工具类
 *
 * @author wuqiwei
 * @date 2021/02/26
 */
public class CodeHj212Utils {

	public static List<CodeHj212> getCodeHj212List() {
		List<CodeHj212> list = new ArrayList<>();
		BaseDao<CodeHj212> dao = new BaseDaoImpl<>();
		Map<String, Object> param = new HashMap<>(16);
		param.put("ALL", "ALL");
		try {
			list = dao.queryByExample(param, CodeHj212.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 根据2017版的code获取对应的名称
	 *
	 * @param code2017 2017版的code
	 * @return 对应的名称
	 */
	public static String getName(String code2017) {
		List<CodeHj212> list = getCodeHj212List();
		for (CodeHj212 codeHj212 : list) {
			if (code2017.equals(codeHj212.getCode2017())) {
				return codeHj212.getName();
			}
		}
		return code2017;
	}

	/**
	 * 根据2005版的code获取对应的2017版code
	 *
	 * @param code2005 2005版的code
	 * @return 对应的2017版code
	 */
	public static String getCode2017By2005(String code2005) {
		List<CodeHj212> list = getCodeHj212List();
		for (CodeHj212 codeHj212 : list) {
			if (code2005.equals(codeHj212.getCode2005())) {
				return codeHj212.getCode2017();
			}
		}
		return code2005;
	}

	/**
	 * 根据河北省版的code获取对应的2017版code
	 *
	 * @param hebei 河北省版的code
	 * @return 对应的2017版code
	 */
	public static String getCode2017ByHebei(String hebei) {
		List<CodeHj212> list = getCodeHj212List();
		for (CodeHj212 codeHj212 : list) {
			if (codeHj212.getCodeHebei().contains(hebei)) {
				return codeHj212.getCode2017();
			}
		}
		return hebei;
	}

}
